﻿using ConfExpert.Forms.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevTeam;

using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo
{
    public partial class KumasEniSec : XForm
    {
        string ProductId;
        int CustomerId;

        public KumasEniSec(string productIds, int customerId)
        {
            InitializeComponent();
            ProductId = productIds;
            CustomerId = customerId;
        }

        public DataTable dtEn
        {
            get
            {
                return gvTop.DataTable().Select("Onay=1").CopyToDataTable();
            }
        }

        private void KumasEniSec_Load(object sender, EventArgs e)
        {

            txtInfo.Caption = "Belirlemek istediğiniz satırı seçip Kaydet'e tıklayın.";
            gvArtikel.Init("GetKumasEn", ProductId, CustomerId);
            gvArtikel.AddDetailGrid(gvTop, "ProductId");

            gvTop.MakeColumnInvisible("Onay");

            gvTop.AddSummary("Qty");

            gvTop.RowClick += new RowClickEventHandler(gvTop_RowClick);

            gvTop.OptionsView.EnableAppearanceOddRow = gvTop.OptionsView.EnableAppearanceEvenRow = false;

            //gvTop.Editable = false;

            gvTop.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(gvTop_RowCellStyle);

            btnKaydet.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
            btnKaydet.ItemClick += btnKaydet_ItemClick;
            gvTop.MakeReadOnly();

            gvArtikel.BestFitColumns();
            gvTop.BestFitColumns();
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvTop.EndEditing();
            this.DialogResult = DialogResult.OK;
        }

        void gvTop_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            int productId = gvArtikel.GetRowCellValue(gvArtikel.FocusedRowHandle, "ProductId").ToInt(-1);
            int RollId = gvTop.GetRowCellValue(gvTop.FocusedRowHandle, "RollId").ToInt(-1);

            foreach (DataRow dr in gvTop.DataTable().Select("ProductId=" + productId.ToString()))
            {
                dr["Onay"] = 0;
            }

            gvTop.SetRowCellValue(gvTop.FocusedRowHandle, "Onay", 1);
        }

        void gvTop_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            //GridView view = sender as GridView;

            if (e.RowHandle > -1)
            {
                int onay = gvTop.GetRowCellValue(e.RowHandle, "Onay").ToInt(-1);
                if (e.Column.FieldName == "En" && onay == 1)
                {
                    e.Appearance.BackColor = Color.Green;
                }
            }
        }

    }
}